<template>
  <el-card>
    <el-row :gutter="10">
      <el-col :span="6">
        <el-input v-model="formData.no" placeholder="请输入会员卡号" />
      </el-col>
      <el-col :span="6">
        <el-input v-model="formData.tel" placeholder="请输入持有人电话" />
      </el-col>
      <el-col :span="6">
        <el-input v-model="formData.name" placeholder="请输入持有人姓名" />
      </el-col>
      <el-col :span="6">
        <el-button type="primary" @click="loadData"  v-permission="'admin'">查询</el-button>
        <el-button type="primary" @click="reset"  v-permission="'admin'">重置</el-button>
      </el-col>
    </el-row>
  </el-card>
  <el-card class="mt">
    <el-table :data="dataList" v-loading="loading">
        <el-table-column label="会员卡号" prop="memberCardNumber" />
        <el-table-column label="卡类型" prop="cardType" />
        <el-table-column label="开卡日期" prop="issueDate" />
        <el-table-column label="持有人姓名" prop="holderName" />
        <el-table-column label="持有人电话" prop="holderPhone" />
        <el-table-column label="卡余额" prop="cardBalance" />
        <el-table-column label="消费记录" width="120">
            <template #default="scope">
               <el-popover title="消费记录" :width="400" trigger="hover" content="aaaa消费记录">
                <template #reference>
                    <el-button type="primary">当日消费记录</el-button>
                </template>
                <el-timeline style="max-width: 200px;">
                    <el-timeline-item v-for="item in scope.row.transactionRecords" :key="item.transactionDate"
                     :timestamp="item.transactionDate" color="#1890ff">    
                     <p>消费金额：{{item.transactionAmount}}</p>     
                     <p>消费类型：{{item.transactionType}}</p>
                    </el-timeline-item>
                </el-timeline>
            </el-popover>
            </template>
        </el-table-column>
        <el-table-column label="有效期至" prop="validityPeriod" />
    </el-table>
    <el-pagination
      class="mt mb fr"
      background
      v-model:current-page="pageInfo.page"
      v-model:page-size="pageInfo.pageSize"
      :page-sizes="[10, 20, 30, 40]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totals"
      @size-change="handleSizechange"
      @current-change="handlePageNochange"
    />
  </el-card>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { useHttp } from '@/hooks/useHttp';

interface FormData {
  no: string;
  tel: string;
  name: string;
}

const formData = ref<FormData>({
  no: '',
  tel: '',
  name: '',
});

const {
  dataList,
  loading,
  totals,
  pageInfo,
  loadData,
  resetPagination,
  handleSizechange,
  handlePageNochange,
} = useHttp('https://www.demo.com/member', formData);

const reset = () => {
    formData.value = {
        no: '',
        tel: '',
        name: '',
    };
    resetPagination();
    loadData();
}
</script>

<style lang="less" scoped></style>
